package psn.hui.stat.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import psn.hui.stat.domain.BaseEntity;
import psn.hui.stat.mapper.StatMapper;
import psn.hui.stat.service.StatService;

@Service
public class StatServiceImpl implements StatService {
	@Autowired
	private StatMapper statMapper;
	/**
	 * 获取客户地区统计数据
	 */
	@Override
	public List<BaseEntity> loadCustomerAreaStatJson() {
		return statMapper.loadCustomerAreaStat();
	}
	/**
	 * 获取年度业务员销售额数据
	 * @param year
	 * @return
	 */
	@Override
	public Map<String, Object> loadSalesmanAnnualSalesStatJson(Integer year) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<BaseEntity> entitylist =  statMapper.loadSalesmanAnnualSalesStatJson(year);
		List<String> names = new ArrayList<String>();
		List<Double> values = new ArrayList<Double>();
		for (BaseEntity entity : entitylist) {
			names.add(entity.getName());
			values.add(entity.getValue());
		}
		map.put("names", names);
		map.put("values", values);
		return map;
	}
	/**
	 * 获取公司年度月份销售额统计数据
	 * @param year
	 * @return
	 */
	@Override
	public List<Double> loadAnnualMonthlySalesStatJson(Integer year) {
		List<Double> dataList = statMapper.loadAnnualMonthlySalesStatJson(year);
		List<Double> statList = new ArrayList<Double>();
		for (Double data : dataList) {
			if(null == data) {
				statList.add((double) 0);
			}else {
				statList.add(data);
			}
		}
		return statList;
	}
	
}
